<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生管理</title>
    <link href="/layui/css/layui.css" rel="stylesheet">
    <link href="/css/custom.form.css" rel="stylesheet">
</head>
<body>
<!--数据与分页-->
<div class="user_table_div">
    <!--多条件查询-->
    <div id="searchParam">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" id="name" placeholder="请输入学生姓名" type="text">
            </div>
            <div class="layui-input-inline ">
                <button class="layui-btn" id="search">查询</button>
            </div>
        </div>
    </div>
    <!--显示数据的表格-->
    <table class="layui-hide" id="user_table" lay-filter="user_table"></table>
    <!--分页相关 View-->
    <div class="layui-laypage-btn" id="laypage"></div>
</div>


<!-- 新增编辑学生View-->
<div class="panel panel-default operation_user" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form action="" class="layui-form " lay-filter="deptInfo" style="width: 700px;margin-top: 10px">
            <input hidden name="id"/>
            <div class="layui-form-item">
                <label class="layui-form-label">学生姓名</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="name" placeholder="学生姓名"
                           type="username">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">班级名</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="zlass" placeholder="班级名"
                           type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">学号</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="sno" placeholder="学号"
                           type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">学院</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="college" placeholder="学院"
                           type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">专业</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="major" placeholder="专业"
                           type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">政治面貌</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="politicalStatus" placeholder="政治面貌"
                           type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">民族</label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="nationality" placeholder="民族"
                           type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label ">性别</div>
                <div class="layui-input-block">
                    <select lay-search lay-verify="" name="sex">
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-filter="submit" lay-submit="" type="submit">保存
                    </button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>

</body>
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<!--新增学生按钮、批量删除 按钮-->
<!--给学生赋予角色按钮-->
<!--shiro:hasPermission="sys:user:role:update"  shiro:hasPermission="sys:user:update" shiro:hasPermission="sys:user:delete" -->
<script>
    layui.use(['jquery', 'form', 'table', 'laypage', 'layer', 'laydate', 'tree', 'transfer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var laypage = layui.laypage
        var layer = layui.layer;
        var laydate = layui.laydate;

        /*分页参数*/
        var searchParam = {
            pageNum: 1,
            pageSize: 10,
            /*以下为多条件查询参数*/
            name: null
        }

        /*动态获取数据*/
        var reloadTreeTable = function () {
            CoreUtil.sendAjax("/dormitory/student/page", searchParam, function (res) {

                //初始化分页器
                laypageTable(res.page.totalCount, searchParam.pageNum);
                //初始化渲染数据
                loadTable(res.page.list);
                if (res.page.list != null) {
                    loadTable(res.page.list);
                }
            }, "GET", false, function (res) {
                //学生列表接口无权限回调
                layer.msg("抱歉！您暂无获取学生列表的权限");
                var noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        }
        //渲染分页插件
        var laypageTable = function (count, currentPage) {
            laypage.render({
                elem: 'laypage'
                , count: count
                , limit: searchParam.pageSize
                , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                , curr: location.hash.replace('#!currentPage=', '')     //获取起始页
                , hash: 'currentPage'                                   //自定义hash值
                , jump: function (obj, first) {
                    if (!first) {
                        searchParam.pageNum = obj.curr;
                        searchParam.pageSize = obj.limit;
                        CoreUtil.sendAjax("/dormitory/student/page", searchParam, function (res) {
                            if (res.page.list != null) {
                                loadTable(res.page.list);
                                laypageTable(res.page.totalCount, searchParam.pageNum);
                            }
                        }, "GET", false, function (res) {
                            //学生列表接口无权限回调
                            layer.msg("抱歉！您暂无获取学生列表的权限");
                            var noAuthorityData = [];
                            loadTable(noAuthorityData);
                        });
                    }
                }
            });
        };
        //渲染table
        var loadTable = function (data) {
            //展示已知数据
            table.render({
                elem: '#user_table'
                // 这个 data 为数组数据，直接 放到 data 上即可。
                , data: data
                , even: true
                , limit: data.length
                , limits: [10, 20, 30, 40, 50]
                , toolbar: '#toolbar'
                , cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'id', title: 'ID', width: 100, sort: true},
                        {field: 'name', title: '学生名', width: 130},
                        {field: 'sno', title: '学号', width: 130},
                        {
                            field: 'sex', title: '性别', width: 80, templet: function (item) {
                                if (null != item.sex) {
                                    if (item.sex === 1) {
                                        return "男";
                                    }
                                    if (item.sex === 2) {
                                        return "女";
                                    }
                                } else {
                                    return null;
                                }
                            }
                        },
                        {field: 'college', title: '学院名', width: 150},
                        {field: 'major', title: '专业名', width: 150},
                        {field: 'zlass', title: '班级', width: 150},
                        {field: 'politicalStatus', title: '政治面貌', width: 150},
                        {field: 'roomName', title: '寝室名', width: 150},
                        {field: 'nationality', title: '民族', width: 150},
                    ]
                ]
            });
        };
        reloadTreeTable();

        //编辑或新增的界面取消事件
        $("#btn_cancel").click(function () {
            //显示表格
            $(".user_table_div").show();
            //隐藏编辑窗口
            $(".operation_user").hide();
            //可以防止在表单事件操作后自动刷新
            return false;
        });

        //执行查询
        $("#search").click(function () {
            searchParam.name = $("#name").val();
            searchParam.pageNum = 1;
            CoreUtil.sendAjax("/dormitory/student/page", searchParam, function (res) {
                if (res.page.list != null) {
                    loadTable(res.page.list);
                    laypageTable(res.page.totalCount, searchParam.pageNum);
                }
            }, "GET", false, function (res) {
                //学生列表接口无权限回调
                layer.msg("抱歉！您暂无获取学生列表的权限");
                var noAuthorityData;
                noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        });


        // 渲染时间
        laydate.render({
            elem: '.createTime'
            , position: 'static'
            , change: function (value, date) { //监听日期被切换
                lay('#testView').html(value);
            }
        });
    });
</script>
</html>

